package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.sys.SysMenu;
import com.atguigu.spzx.manager.mapper.SysMenuMapper;
import com.atguigu.spzx.manager.service.SysMenuService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-06-20:09
 */
@RestController
@RequestMapping("/admin/system/menu")
public class SysMenuController {

    @Resource
    SysMenuService sysMenuService;

    @GetMapping("/findNestdMenus")
    public Result findNestdMenus(){
        List<SysMenu> parentMenus = sysMenuService.findNestdMenus();
        return Result.ok().data(parentMenus);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        sysMenuService.deleteById(id);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id){
       SysMenu sysMenu = sysMenuService.getById(id);
        return Result.ok().data(sysMenu);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody SysMenu sysMenu){
        sysMenuService.updateById(sysMenu);
        return Result.ok();
    }

    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return Result.ok();
    }
    @GetMapping("/findDynamicMenus")
    public Result findDynamicMenus(){
        List<SysMenu> menuVos = sysMenuService.findDynamicMenus();
        return Result.ok().data(menuVos);
    }
}
